var EXPORTED_SYMBOLS = ["Command"];



Components.utils.import("resource://SynoLoader/Util.js"); 


Command = function(){

this.connect = false;
this.timeout = 10000;
this.parameter = "0";
this.url = "http:/";
this.http_request =  Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
	                    .createInstance(Components.interfaces.nsIXMLHttpRequest);
};





Command.prototype.onsuccess	= function(http_request){Util.log("onsuccess");};  
Command.prototype.onfaild	= function(http_request){Util.log("onfaild");};                    


Command.prototype.onreadystatechange= function()
{
if (this.http_request.readyState == 4) 
		{
				switch(this.http_request.status)
				{
				case 200:
					this.onsuccess(this.http_request);
					break;
				default:
					this.onfaild(this.http_request);
					break;
				}
		}
};

Command.prototype.send = function(){
	
	this.http_request.timeout = Command.prototype.timeout;
    this.http_request.ontimeout = function () {  this.onfaild(Command.prototype.http_request);   };
    var self = this;
	this.http_request.onreadystatechange =  function() { self.onreadystatechange(); };
	this.http_request.open('POST',this.url, true);
	this.http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	this.http_request.setRequestHeader("Content-length", this.parameter.length);
	this.http_request.send(this.parameter);

};

Command.prototype.onfaild	= function(http_request)
{
	this.connect = false;
  	if(http_request.statusText=="")
	{
  		Util.log("HttpRequest -> No status available, no response, or no server.");
	}
	else
	{
		Util.log("HttpRequest -> " + this.http_request.statusText);
	}
};


